import type { TreeNode } from '@/types/treeType';

// 获取所有可见节点
export function getVisibleNodes(nodes: TreeNode[]): TreeNode[] {
    const result: TreeNode[] = [];

    function traverse(nodes: TreeNode[]) {
        nodes.forEach(node => {
            result.push(node);
            if (node.expanded && node.children) {
                traverse(node.children);
            }
        });
    }

    traverse(nodes);
    return result;
}

// 切换全部展开状态
export function toggleAllNodes(nodes: TreeNode[], expanded: boolean): TreeNode[] {
    return nodes.map(node => ({
        ...node,
        expanded,
        children: node.children ? toggleAllNodes(node.children, expanded) : undefined
    }));
}
